package org.zjx.app.action.route;


import org.zjx.analysis.analyze.game.GameAnalysis;
import org.zjx.command.entity.screen.Address;
import org.zjx.window.action.Action;
import org.zjx.window.window.IWindow;

import java.awt.event.KeyEvent;

public class BackToSectAction extends Action {
    private final Address targetAddress;

    public BackToSectAction(IWindow targetWindow, Address targetAddress) {
        super(targetWindow, true);
        this.targetAddress = targetAddress;
    }

    @Override
    protected void doExecute() throws Exception {
        if (!getAddressNow().near(targetAddress,5)){
            targetWindow.actions().hotkey(KeyEvent.VK_F8).delay(500);
        }
    }

    public Address getAddressNow() {
        GameAnalysis gameAnalysis = new GameAnalysis(targetWindow);
        return gameAnalysis.getAddress();
    }
}
